from config import HOST


class ApiTrustRecharge:
    # 初始化
    def __init__(self, session):
        self.session = session
        # url
        self.__url_approve = HOST + "/member/realname/approverealname"
        self.__url_get_approve = HOST + "/member/member/getapprove"
        self.__url_trust = HOST + "/trust/trust/register"
        self.__url_img_code = HOST + "/common/public/verifycode/{}"
        self.__url_recharege = HOST + "/trust/trust/recharge"

    # 1、认证接口 封装
    def api_approve(self, realname, card_id):
        # 请求参数
        data = {
            "realname": realname,
            "card_id": card_id
        }
        # 难点：multipart/form-data   请求参数数据 data + files
        # 请求方法
        return self.session.post(url=self.__url_approve, data=data, files={"x": "y"})

    # 2、获取认证接口 封装
    def api_get_approve(self):
        # 请求方法
        return self.session.post(url=self.__url_get_approve)

    # 3、请求后台开户接口 封装
    def api_trust(self):
        # 请求方法
        return self.session.post(url=self.__url_trust)

    # 4、获取充值图片验证码接口 封装
    def api_img_code(self, random):
        # 请求方法
        return self.session.get(url=self.__url_img_code.format(random))

    # 5、请求后台充值接口 封装
    def api_recharge(self, valicode):
        # 请求参数
        data = {
            "paymentType": "chinapnrTrust",
            "amount": 10000,
            "formStr": "reForm",
            "valicode": valicode
        }
        # 请求方法
        return self.session.post(url=self.__url_recharege, data=data)
